const tokens = {
  admin: {
    token: "admin-token"
  },
  editor: {
    token: "editor-token"
  }
};

const users = {
  "admin-token": {
    roles: ["admin"],
    introduction: "我是超级管理员",
    avatar:
      "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=900739219,1112472094&fm=26&gp=0.jpg",
    name: "超管"
  },
  "editor-token": {
    roles: ["editor"],
    introduction: "我是一名编辑",
    avatar:
      "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=900739219,1112472094&fm=26&gp=0.jpg",
    name: "小编"
  }
};

module.exports = [
  // 用户登录
  {
    url: "/vue-admin-template/user/login",
    type: "post",
    response: config => {
      const { username } = config.body;
      const token = tokens[username];

      // mock error
      if (!token) {
        return {
          code: 60204,
          message: "账号或者密码不正确."
        };
      }

      return {
        code: 20000,
        data: token
      };
    }
  },

  // 获取用户信息
  {
    url: "/vue-admin-template/user/info.*",
    type: "get",
    response: config => {
      const { token } = config.query;
      const info = users[token];

      // mock error
      if (!info) {
        return {
          code: 50008,
          message: "登录失败，无法获取用户详细信息。"
        };
      }

      return {
        code: 20000,
        data: info
      };
    }
  },

  // user logout
  {
    url: "/vue-admin-template/user/logout",
    type: "post",
    response: _ => {
      return {
        code: 20000,
        data: "success"
      };
    }
  }
];
